package com.kgcx.organization.controller;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.organization.domain.Supplier;
import com.kgcx.organization.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "供应商接口", tags = "供应商接口")
@RestController
@RequestMapping("supplier")
public class SupplierController extends BaseController {
    @Autowired
    private SupplierService supplierService;

    @ApiOperation(value = "查询供应商", httpMethod = "GET", notes = "这是用来查询供应商的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "供应商ID", required = true, paramType = "query", dataType = "String", dataTypeClass = Long.class),
    })
    @GetMapping("getSupplier")
    public ReturnData<Supplier> getSupplier() {
        RequestData requestData = this.getRequestData();
        Supplier supplier = supplierService.getSupplier(requestData.getLong("kid"));
        return new ReturnData<>(supplier);
    }

    @ApiOperation(value = "查询供应商", httpMethod = "GET", notes = "这是用来查询供应商的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "name", value = "名称", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "cityId", value = "城市id", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "licenseId", value = "许可证号", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("getSupplierList")
    public ReturnData<List<Supplier>> getSupplierList() {
        RequestData requestData = this.getRequestData();
        List<Supplier> supplierList = supplierService.getSupplierList(requestData);
        return new ReturnData<>(supplierList);
    }

    @ApiOperation(value = "新增供应商", httpMethod = "POST", notes = "这是用来新增供应商的接口")
    @PostMapping("addSupplier")
    public ReturnData addSupplier(@RequestBody Supplier supplier) {
        supplierService.addSupplier(supplier);
        return new ReturnData();
    }

    @ApiOperation(value = "修改供应商", httpMethod = "POST", notes = "这是用来修改供应商的接口")
    @PostMapping("updateSupplier")
    public ReturnData updateSupplier(@RequestBody Supplier supplier) {
        supplierService.updateSupplier(supplier);
        return new ReturnData();
    }

    @ApiOperation(value = "删除供应商", httpMethod = "POST", notes = "这是用来删除供应商的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "用户ID", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping("removeSupplier")
    public ReturnData removeSupplier(@RequestParam Long kid) {
        supplierService.removeSupplier(kid);
        return new ReturnData();
    }
}
